package com.chen.util;

public class PageSupport {
    //数据库中数据总条数
    private int totalCount=0;
    //当前页码
    private int currentPageNo=1;
    //每页显示条数（页面大小）
    private int pageSize=0;
    //总页数
    private int totalPageCount=1;

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {

        if (totalCount>0){
            this.totalCount = totalCount;
            this.setPageCountByRs();
        }
    }

    public int getCurrentPageNo() {
        return currentPageNo;
    }

    public void setCurrentPageNo(int currentPageNo) {
        //判断输入页码是否大于0
        if (currentPageNo>0 && currentPageNo<=totalPageCount){
            this.currentPageNo = currentPageNo;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        //判断页面大小是否大于0
        if (pageSize>0){
            this.pageSize = pageSize;
        }
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        //判断totalPageCount是否大于0
        if (totalPageCount>0){
            this.totalPageCount = totalPageCount;
        }
    }
    public void setPageCountByRs(){
        //判断是否定义了pageSize
        if (pageSize>0){
            //能走到这说明totalCount>0 && pageSize>0
            //那么相除的结果要么为0，要么大于0
            if (totalCount%pageSize == 0){
               totalPageCount = totalCount / pageSize;
            }else {
                totalPageCount = (totalCount/pageSize)+1;
            }
        }else {
            totalPageCount = 0;
        }
    }
}
